package cn.hamm.spms.module.open.api.test;

import cn.hamm.airpower.access.Permission;
import cn.hamm.airpower.annotation.Description;
import cn.hamm.airpower.api.Api;
import cn.hamm.airpower.api.ApiController;
import cn.hamm.airpower.api.Json;
import cn.hamm.airpower.open.OpenApi;
import cn.hamm.airpower.open.OpenRequest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.ArrayList;
import java.util.List;

/**
 * <h1>Controller</h1>
 *
 * @author Hamm.cn
 */
@Api("openApi/test")
@Description("测试API")
@Permission(login = false)
public class OpenTestController extends ApiController {
    @Description("test")
    @PostMapping("test")
    @OpenApi
    public Json test(@RequestBody @Validated OpenRequest openRequest) {
        return Json.data(openRequest.parse(OpenTestModel.class));
    }

    @Description("test")
    @PostMapping("testArr")
    @OpenApi
    public Json testArr(@RequestBody @Validated OpenRequest openRequest) {
        List<OpenTestModel> list = new ArrayList<>();
        list.add(new OpenTestModel().setName("test").setAge(1));
        list.add(new OpenTestModel().setName("test1").setAge(2));
        return Json.data(list);
    }
}
